<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">采购收货确认</block>
		</cu-custom>
		
		<form>
			<view class="cu-form-group">
				<view class="title">送货号输入:</view>
				<input placeholder="请输入送货单号" name="input" @input="changWo" v-model="myFormData.dnNumber"></input>
			</view>
			<view class="cu-form-group">
				<view class="title" style="width: 200rpx;">客户料号:</view>
				<view class="action" style="width: 222px;">
					<text class="text-grey">{{myFormData.custCode}}</text>
				</view>
			</view>
<!-- 			<view class="cu-form-group">
				<view class="title" style="font-size: 42rpx;">{{compQtyName + ":"}}</view>
				<input type="number" :focus="focusState" :placeholder="'输入' + compQtyName" name="input"  v-model="myFormData.qty"></input>
			</view> -->
			<view class="cu-form-group">
				<view class="title" style="width: 200rpx;">产品名称:</view>
				<view class="action" style="width: 222px;">
					<text class="text-grey">{{myFormData.name}}</text>
				</view>
			</view>			
		   <view class="cu-form-group">
			   <view class="title" style="width: 200rpx;">领料人员</view>
			   <view class="action" style="width:222px;">
				<!-- <text class="text-grey" >{{myFormData.employee}}</text> -->
				<input placeholder="请输入领料人工号" name="input" v-model="myFormData.employee"></input>
			   </view>
		   </view>			
			<view class="cu-form-group container-btn">
					<button class="cu-btn bg-blue lg" :disabled="completeFlag" @click="onSubmit(0)">确定</button>
					<button  class="cu-btn bg-green lg" @click="scanApp" style="margin-left: 46px;">扫码</button>
			</view>			
			<view class="cu-form-group">
				<view class="title">物料查找:</view>
				<input placeholder="请输入查找数据" name="input" @input="changSearch" v-model="searchValue"></input>
			</view>
<!-- 			<view style="margin-top: 10px;">
					<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据"
						@selection-change="selectionChangeOrder">
						<uni-tr>
							<uni-th width="20" align="center">序号</uni-th>
							<uni-th align="center" width="140">领料数量</uni-th>	
							<uni-th align="center">需求数量</uni-th>	
							<uni-th align="center">已领数量</uni-th>							
							<uni-th width="150" align="center">物料编码</uni-th>
							<uni-th width="150" align="center">物料类型</uni-th>
							<uni-th align="center">物料名称</uni-th>
							<uni-th align="center">物料规格</uni-th>
							<uni-th align="center">单位</uni-th>
							<uni-th align="center">库存数量</uni-th>
							<uni-th align="center">物料描述</uni-th>	
							<uni-th align="center">版本</uni-th>																												
						</uni-tr>
						<uni-tr v-for="(item, index) in searchMaterialDatas" :key="index"
							:class="{ 'highlight-row': isRowHighlighted(item) }">
							<uni-td align="center">{{ index + 1 }}</uni-td>
							<uni-td align="center">
						    	<input placeholder="请输入数量" class="input-border" name="input" type="number"  v-model="item.inputQty"></input>
							</uni-td>							
							<uni-td align="center">{{ item.qty }}</uni-td>
							<uni-td align="center">{{ item.qtyReceipt ? item.qtyReceipt : 0}}</uni-td>								
							<uni-td align="center">{{ item.materialCode ? item.materialCode : '' }}</uni-td>
							<uni-td align="center">{{ item.materialType ? item.materialType : '' }}</uni-td>
							<uni-td align="center">{{ item.materialName ? item.materialName : ''}}</uni-td>
							<uni-td align="center">{{ item.materialModel ? item.materialModel : ''}}</uni-td>
							<uni-td align="center">{{ item.unitName ? item.unitName : '' }}</uni-td>
							<uni-td align="center">{{ item.invQty ? item.invQty : 0 }}</uni-td>	
							<uni-td align="center">{{ item.description ? item.description :'' }}</uni-td>	
							<uni-td align="center">{{ item.materialVer ? item.materialVer : ''}}</uni-td>
						</uni-tr>
					</uni-table>
					<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="changePage" /></view>
			</view>	 -->		
<!-- 			<view class="example-body">
				<uni-drawer ref="showLeft" mode="left" :width="280" :mask-click="true" @change="changeDraw($event,'showLeft')">
					<view class="scroll-view">
						<scroll-view class="scroll-view-box" scroll-y="true">							
							<view class="uni-flex uni-row" style="-webkit-flex: 1;flex: 1; margin-top: 70px; margin-left: 10px; line-height: 2;" >
								<view style="display: flex;">
									<view class="text" style="width: 200rpx;">工序</view>
									<view class="text" style="width: 100rpx;">数量</view>
									<view class="text" style="width: 200rpx;">员工</view>
									<view class="text" style="width: 200rpx;">操作</view>
									<view class="text" style="width: 240rpx;">时间</view>
								</view>
								<view style="display: flex;" v-for="item in recpList" :key="item">
									<view class="text" style="width: 200rpx;">{{item.processId_dictText}}</view>
									<view class="text" style="width: 100rpx;"> {{item.qty}}</view>
									<view class="text" style="width: 200rpx;"> {{item.createBy_dictText}}</view>
									<view class="text" style="width: 200rpx;"> {{item.dataFrom}}</view>
									<view class="text" style="width: 240rpx;"> {{item.createTime.substr(0, 10)}}</view>
								</view>
							</view>
						</scroll-view>
					</view>
				</uni-drawer>
			</view> -->
			<view class="example-body">
				<!-- <tabls refs="tabls"></tabls> -->
				<view class="container">
				  <!-- 标签栏 -->
				  <scroll-view class="tabs" scroll-x scroll-with-animation>
				    <view 
				      v-for="(tab, index) in tabs" 
				      :key="index" 
				      class="tab-item" 
				      :class="{ 'active': activeTab === index }"
				      @click="switchTab(index)"
				    >
				      {{ tab.title }}
				    </view>
				  </scroll-view>
				
				  <!-- 内容区域 -->
				  <view class="content">
				    <view v-for="(tab, index) in tabs" :key="index" v-if="activeTab === index" class="tab-content">
				      <uni-table ref="table" :loading="tab.loading" border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
				        <uni-tr>
				          <uni-th v-for="header in tab.columns" :key="header.key" :width="header.width" :align="header.align">
				            {{ header.title }}
				          </uni-th>
				        </uni-tr>
				        <uni-tr v-for="(item, rowIndex) in tab.data" :key="rowIndex">
				          <uni-td v-for="(header, colIndex) in tab.columns" :key="colIndex">
				            <!-- 处理序号列 -->
				            <template v-if="header.key === 'index'">
				              {{ rowIndex + 1 }}
				            </template>
							<template v-else-if = "header.key === 'qtyBal'">
							 <input placeholder="请输入数量" class="input-border" name="input" type="number"  v-model="item[header.key]"></input>
							</template>
				            <!-- 处理其他列 -->
				            <template v-else>
				              {{ item[header.key] ? item[header.key] : '' }}
				            </template>
				          </uni-td>
				        </uni-tr>
				      </uni-table>
				    </view>
				  </view>
				</view>
		    </view>		
		</form>
	</view>
</template>

<script>
	import { USER_INFO} from "@/common/util/constants"
	import socket from '@/common/js-sdk/socket/socket.js'
	import configService from '@/common/service/config.service.js';
    import { forEach } from "../../common/luch-request/utils";
	import tabls from '@/pages/report/tabs.vue'
    import {scanCode } from "@/uni_modules/lime-scan"  
	export default {
		name:'inputWorkProcessQty',
		components:{
			tabls,
		},
		data() {
			return {
				focusState:false,
				searchValue : '',
				index: -1,
				switchC: true,
				empProcess:false,
				imgList: [],
				range: [],		
				materialDatas : [],
				searchMaterialDatas : [],
				uploadUrl:"/sys/common/upload",
				processIds:'',
				productType : '',
				compQtyName : '完工数量',
				completeFlag : false ,
				isLastProcess: false,
				workprocess: null,
				workProcessItems : null,
				userInfo: null,
				workOrderProcesses:[],
				workOrderGroupId : null,
				myFormData:{
					woQty:'',
					custCode:'',
					name:'',
					productVer:'',		
				    employee:'',
					employeeId:'',
					workOrderNumber:'',
					avatar:'',
					realname:'',
					username:'',
					sex:1,
					birthday:'',
					orgCode:'',
					workNo:'',
					phone:'',
					email:'',
					id:'',
				},
				title: 'uni-fab',
				directionStr: '垂直',
				horizontal: 'left',
				vertical: 'bottom',
				direction: 'horizontal',
				pattern: {
					color: '#7A7E83',
					backgroundColor: '#fff',
					selectedColor: '#007AFF',
					buttonColor: '#007AFF',
					iconColor: '#fff',
					icon:'scan'
				},
				is_color_type: false,
				content: [{
						iconPath: '/static/image.png',
						selectedIconPath: '/static/image-active.png',
						text: '相册',
						active: false
					},
					{
						iconPath: '/static/home.png',
						selectedIconPath: '/static/home-active.png',
						text: '首页',
						active: false
					},
					{
						iconPath: '/static/star.png',
						selectedIconPath: '/static/star-active.png',
						text: '收藏',
						active: false
					}
				],
				oldMyformData : {},
				recpList:[],
				url : {
					list: '/wom/womWorkOrder/list-receipt',
				},
				activeTab: 0, // 当前激活的标签索引
				tabs: [
				  {
				    title: '待领料',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'salseOrderNumber', width: '150', align: 'center' },
					  { title: '物料名称', key: 'realName', width: '100', align: 'center' },
					  { title: '物料编码', key: 'materialCode', width: '100', align: 'center' },
					  { title: '物料规格', key: 'materialModel', width: '100', align: 'center' },					  
					  { title: '待领数量', key: 'qtyBal', width: '100', align: 'center' },
					  { title: '库存数量', key: 'invQty', width: '100', align: 'center' },
					  { title: '已领数量', key: 'qtyReceipt', width: '100', align: 'center' },
					  { title: '毛需求数量', key: 'qty', width: '100', align: 'center' },
					  { title: '物料类型', key: 'materialType', width: '100', align: 'center' },
					  { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				      { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
					  { title: '工单数量', key: 'itemQty', width: '100', align: 'center' },
					  { title: 'BOM数量', key: 'bomQty', width: '100', align: 'center' },					  
				    ],
				    data: [
				    ]
				  },
				  {
				    title: '物料表',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'salseOrderNumber', width: '150', align: 'center' },
					  { title: '物料名称', key: 'realName', width: '100', align: 'center' },
					  { title: '物料编码', key: 'materialCode', width: '100', align: 'center' },
					  { title: '物料规格', key: 'materialModel', width: '100', align: 'center' },					  
					  { title: '已领数量', key: 'qtyReceipt', width: '100', align: 'center' },
					  { title: '毛需求数量', key: 'qty', width: '100', align: 'center' },
					  { title: '库存数量', key: 'invQty', width: '100', align: 'center' },
					  { title: '物料类型', key: 'materialType', width: '100', align: 'center' },
					  { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				      { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
					  { title: '工单数量', key: 'itemQty', width: '100', align: 'center' },
					  { title: 'BOM数量', key: 'bomQty', width: '100', align: 'center' },	
				    ],
				    data: []
				  },
				  {
				    title: '待领半成品',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'salseOrderNumber', width: '150', align: 'center' },
				  					  { title: '产品名称', key: 'name', width: '100', align: 'center' },
										{ title: '待领数量', key: 'qtyBal', width: '100', align: 'center' },										
										{ title: '库存数量', key: 'inventoryQty', width: '100', align: 'center' },
										{ title: '已领数量', key: 'qtyIssue', width: '100', align: 'center' },
										{ title: '产品编码', key: 'code', width: '100', align: 'center' },
										{ title: '客户料号', key: 'custCode', width: '100', align: 'center' },		
				  					  { title: '描述', key: 'description', width: '100', align: 'center' },
				  					  { title: '图号', key: 'drawingNo', width: '100', align: 'center' },
				  					  { title: '版本', key: 'productVer', width: '100', align: 'center' },
				  					  { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				                      { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
				  					  { title: '工单数量', key: 'qty', width: '100', align: 'center' },
									  { title: '入库数量', key: 'qtyInStork', width: '100', align: 'center' },

				    ],
				    data: []
				  },
				  {
				    title: '半成品表',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'salseOrderNumber', width: '150', align: 'center' },
				  					  { title: '产品名称', key: 'name', width: '100', align: 'center' },
				  					  { title: '产品编码', key: 'code', width: '100', align: 'center' },
				  					  { title: '客户料号', key: 'custCode', width: '100', align: 'center' },		
                                      { title: '工单数量', key: 'qty', width: '100', align: 'center' },
									  { title: '入库数量', key: 'qtyInStork', width: '100', align: 'center' },
									  { title: '已领数量', key: 'qtyIssue', width: '100', align: 'center' },
				  					  { title: '描述', key: 'description', width: '100', align: 'center' },
				  					  { title: '图号', key: 'drawingNo', width: '100', align: 'center' },
				  					  { title: '版本', key: 'productVer', width: '100', align: 'center' },
				  					  { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				                      { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
									  { title: '库存数量', key: 'inventoryQty', width: '100', align: 'center' },
				  					 
				    ],
				    data: []
				  },
				],
				selectedItems : [],
			};
		},
		onLoad: function (option) {
			// this.getEmployee()
		},
		created(){
			this.oldMyformData = this.myFormData
			this.userInfo = uni.getStorageSync(USER_INFO)
			this.myFormData.employee = this.userInfo.realname
			this.myFormData.employeeId = this.userInfo.id
			// this.focusState = true
			this.getEmployee()		
		    // this.scan()
			console.log(this.userInfo)			
		},
		methods: {
			switchTab(index) {
			  this.activeTab = index;
			  if (this.activeTab == 0) {
				  this.getWorkOrderMaterialData(this.workOrderGroupId)
			  }
			  if (this.activeTab == 1) {
                  this.getWorkOrderMaterialAllData(this.workOrderGroupId)
			  }
			  if (this.activeTab == 2) {
                 this.getWorkOrderIssueDataByGroup(this.workOrderGroupId)
			  }
			  if (this.activeTab == 3) {
                  this.getWorkOrderByGroup(this.workOrderGroupId)
			  }
			},
			// 处理表格选中行变化的方法
			selectionChange(e) {
			  this.selectedItems = e.detail.index
			  console.log('选中的行数据:', this.selectedItems);
			},
			changSearch(val) {
			  if (val.detail.value) {
				  let _val = val.detail.value
				  this.searchMaterialDatas =  this.materialDatas.filter((p)=>{
					  return (p.materialCode.includes(_val) || p.materialType.includes(_val) || p.materialName.includes(_val) || p.materialModel.includes(_val))
				  })
			  }	else {
				  this.searchMaterialDatas =  this.materialDatas
			  }
			},
			isRowHighlighted(item) {
				// 根据你的条件返回true或false
				// 例如，如果item的某个属性等于特定值，则返回true
				return item.colorProperty == '2';
			},			
			// 抽屉状态发生变化触发
			changeDraw(e, type) {
				console.log((type === 'showLeft' ? '左窗口' : '右窗口') + (e ? '打开' : '关闭'));
				this[type] = e
			},
			showDrawer(e) {
				this.$refs[e].open()
			},
			// 关闭窗口
			closeDrawer(e) {
				this.$refs[e].close()
			},
			dispList(item){
				this.$http.get(this.url.list,{params:{workOrderItemId:item.workOrderItemId,processId:item.processId,workOrderProcessId:item.id}}).then(res=>{
					console.log("res::receipt list >",res)
			        if (res.data.result.records) {
						this.recpList = res.data.result.records 
						console.log(this.recpList)
						this.showDrawer('showLeft')
					}
				})
			},
			setFocus() {
				let that = this
				this.$nextTick(()=>{
					setTimeout(() => {
								that.focusState = true
						},1000)
				})

			},
			changWo(e) {
				console.log(e)
				if (e.detail.value && e.detail.value.length>11) {
					this.myFormData.workOrderNumber = e.detail.value
					this.getWorkOrderData();
				}
			},
			trigger(e) {
				console.log(e)
				this.content[e.index].active = !e.item.active
				uni.showModal({
					title: '提示',
					content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定')
						} else if (res.cancel) {
							console.log('用户点击取消')
						}
					}
				})
			},
			fabClick() {
				uni.showToast({
					title: '点击了悬浮按钮',
					icon: 'none'
				})
			},
			getEmployee() {
				this.processIds = ''
				console.log("beging find employee.")
				this.$http.get("/bas/basEmployee/list",{params:{code:this.userInfo.username}}).then(res=>{
					console.log("res::employee>",res)
					if (res.data.result.records[0]) {
						this.processIds = res.data.result.records[0].processIds
					}					
				})
			},
			scanApp() {
				let that = this
				this.focusState = false
				scanCode({
					params: '{"showVibrate": true,"showBeep": true,"showPhotoAlbum": true,"showLightController": true,"supportZoom": true,"scanColor": "#ff0000","fullScreenScan":true}',  
					success: (res) => {  
						const innerAudioContext = uni.createInnerAudioContext();
																		innerAudioContext.autoplay = true;
																		innerAudioContext.src = 'https://www.suzi-info.com/13193.wav';  //音频地址
																		innerAudioContext.onPlay(() => {
																			console.log('开始播放');
																		});
																		innerAudioContext.onError((res) => {
																		  console.log(res.errMsg);
																		  console.log(res.errCode);
																		});
																		
						let obj = res
						// let obj = JSON.parse(res)
						if (obj.errMsg == 'ok') {
							let scanResults = obj.result
							let scanDataRes = scanResults?.split('/')
							
							that.myFormData.workOrderNumber = scanDataRes[0] //res.result.split('/')[0]
							that.myFormData.qty = ''						
							that.getWorkOrderData();
						}
					}
				});	
			},
			scan(){
				let that = this
				// this.completeFlag = false
				this.focusState = false
				 console.log("进来了")
				// #ifndef H5
				uni.scanCode({
				    success: function (res) {
									  const innerAudioContext = uni.createInnerAudioContext();
												innerAudioContext.autoplay = true;
												innerAudioContext.src = 'https://www.suzi-info.com/13193.wav';  //音频地址
												innerAudioContext.onPlay(() => {
													console.log('开始播放');
												});
												innerAudioContext.onError((res) => {
												  console.log(res.errMsg);
												  console.log(res.errCode);
												});
						that.myFormData.workOrderNumber = res.result.split('/')[0]
						that.myFormData.qty = ''						
						that.getWorkOrderData();
				    }
				});
				// #endif
				// #ifdef H5
				this.$tip.alert("暂不支持")
				// #endif
			},
			change(val) {
				console.log("val :",val)
				this.myFormData.balanceQty = this.workProcessItems[val].balanceQty
				this.myFormData.processSeq = this.workProcessItems[val].processSeq
				this.myFormData.qtyPreProcess = this.workProcessItems[val].qtyPreProcess
				this.myFormData.limitedProcessScan = this.workProcessItems[val].limitedProcessScan //限制扫码转序数量				
				if (this.productType == 2 && val == this.range[this.range.length - 1].value) {
					this.compQtyName = "入库数量"
				} else {
					this.compQtyName = "完工数量"
				}
			},
			getWorkOrderData(){
				let that = this
				this.completeFlag = false
				if(!this.myFormData.workOrderNumber){
					this.$tip.alert('请输入工单号码！');
					return false
				}
				this.pageCurrent = 1
				this.pageSize = 1000
				let params = {
					'queryName' : '',
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc'
				}
				let superArr = []
				// superArr.push({"rule":"eq","type":"string","val":'3',"field":"op.status"})
				superArr.push({"rule":"eq","type":"string","val":this.myFormData.workOrderNumber,"field":"item.workOrderNumber"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))				
				this.loading = true				
				this.$http.get("/wom/womWorkOrder/list",{params:params}).then(res=>{
					this.loading = false
					let data = res.data.result.records
					console.log("res::workOrderNumber list>",data)					
					//status = 5 取消
					//status = 4 暂停
					if (data && data.length>0 ){		
						if (data[0].status == 5) {
							this.$tip.toast('工单已经取消！')
							return
						}
						this.workOrderGroupId = data[0].workOrderGroupId
						this.myFormData = Object.assign({},data[0])
						this.myFormData.employee = this.userInfo.username
						if (this.activeTab == 1) {
							this.getWorkOrderMaterialAllData(data[0].workOrderGroupId)
						}
						if (this.activeTab == 0) {
							if (data[0].status == 4) {
								this.$tip.toast('工单已经暂停,暂停领料！')							
							} else {
								this.getWorkOrderMaterialData(data[0].workOrderGroupId)
							}							
						}
						if (this.activeTab == 2) {
							this.getWorkOrderIssueDataByGroup(data[0].workOrderGroupId)
						}
						if (this.activeTab == 3) {
							this.getWorkOrderByGroup(data[0].workOrderGroupId)
						}

					} else {
						this.$tip.toast('未找到工单数据！')
					}					
				})
			},	
			getWorkOrderByGroup(groupId){
				let that = this
				this.pageCurrent = 1
				this.pageSize = 1000
				let params = {
					'queryName' : '',
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc'
				}
				let superArr = []
				superArr.push({"rule":"eq","type":"string","val":groupId,"field":"item.workOrderGroupId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))				
				this.loading = true				
				this.$http.get("/wom/womWorkOrder/list",{params:params}).then(res=>{
					this.loading = false
					let data = res.data.result.records
					console.log("res::workOrderNumber list>",data)					
					if (data && data.length>0 ){		
						this.tabs[3].data = data				
					} else {
						this.$tip.toast('未找到工单数据！')
					}					
				})
			},
			getWorkOrderIssueDataByGroup(groupId){
				let that = this
				this.pageCurrent = 1
				this.pageSize = 1000
				let params = {
					'queryName' : '',
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
					'isSemiProductIssue' : true,
				}
				let superArr = []
				superArr.push({"rule":"eq","type":"string","val":groupId,"field":"item.workOrderGroupId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))				
				this.loading = true				
				this.$http.get("/wom/womWorkOrder/list",{params:params}).then(res=>{
					this.loading = false
					let data = res.data.result.records
					console.log("res::workOrderNumber list>",data)					
					if (data && data.length>0 ){		
						data.forEach((item)=>{
							item.qtyBal = item.qty - (item.qtyIssue ? item.qtyIssue : 0)
						})
						this.tabs[2].data = data				
					} else {
						this.$tip.toast('未找到工单数据！')
					}					
				})
			},
			getWorkOrderMaterialAllData(workOrderGroupId){
				let that = this
				this.tabs[1].data = []
				this.completeFlag = false
				this.pageCurrent = 1
				this.pageSize = 1000
				let params = {
					'queryName' : '',
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',

				}
				let superArr = []
				// superArr.push({"rule":"eq","type":"string","val":'3',"field":"op.status"})
				superArr.push({"rule":"eq","type":"string","val":workOrderGroupId,"field":"work_material.workOrderGroupId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))				
				this.loading = true				
				this.$http.get("/wom/womWorkOrderMaterial/list",{params:params}).then(res=>{
					this.loading = false
					let data = res.data.result.records
					console.log("res::workOrderMaterial all list>",data)					
					//status = 5 取消
					//status = 4 暂停					
					if (data && data.length >0){					
                       this.tabs[1].data = data
						// that.setFocus()
					} else {
						this.$tip.toast('未找到工单数据！')
					}					
				})
			},					
			getWorkOrderMaterialData(workOrderGroupId){
				let that = this
				this.tabs[0].data = []
				this.pageCurrent = 1
				this.pageSize = 1000
				let params = {
					'queryName' : '',
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
					'unsell' : true
				}
				let superArr = []
				// superArr.push({"rule":"eq","type":"string","val":'3',"field":"op.status"})
				superArr.push({"rule":"eq","type":"string","val":workOrderGroupId,"field":"work_material.workOrderGroupId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				this.loading = true
				this.$http.get("/wom/womWorkOrderMaterial/list",{params:params}).then(res=>{
					this.loading = false
					let data = res.data.result.records
					console.log("res::workOrderMaterial list>",data)					
					//status = 5 取消
					//status = 4 暂停					
					if (data && data.length>0){					
                        data.forEach((item)=>{
							item.qtyBal = item.qty - (item.qtyReceipt ? item.qtyReceipt : 0)
						})
						this.tabs[0].data = data
					} else {
						this.$tip.toast('未找到工单数据！')
					}					
				})
			},			
			saveSemiProductIssue(item) { 
				let that = this
				let flag = true
				let saveFlag = false
				if (!this.tabs[2].data || this.tabs[2].data.length == 0) {
								  this.$tip.toast('没有可提交的数据！')
								  return
				}
				if (this.activeTab == 2 && this.selectedItems.length == 0) {
								  this.$tip.toast('没有可提交的数据！')
								  return
				}
				// 将选中的行序号存储到 Set 中
				const selectedIndexSet = new Set(this.selectedItems);
				const datas = this.tabs[2].data.filter((item, index) => {
				  return selectedIndexSet.has(index) && item.qty > 0;
				});
				
				datas.forEach(item => {
								  item.inputQty = item.qtyBal
				})
				console.log(datas)
				let error1 = []
				let error2 = []
				datas.forEach((item,index)=>{
								   let balQty = item.qty - 0 - (item.qtyIssue ? item.qtyIssue : 0)
								   let inputQty = item.inputQty ? item.inputQty : 0
								   let invQty = item.inventoryQty ? item.inventoryQty : 0
								   if (inputQty > 0) {
								  					  saveFlag = true
								   }
								   if (inputQty > balQty) {
									   error1.push(index+1)
								  					  this.$tip.toast('行:' + (index +1) +  ' 数量超出了剩余发料数量！')
								  					  flag = false
								  					  return
								   }				  
								   if (inputQty  > invQty) {
									   error2.push(index+1)
								  					 this.$tip.toast('行:' + (index + 1) +  ' 数量超出了库存可发料数量！')
								  					 flag = false
								  					 return
								   }
				})
				if (error1.length>0) {
								 this.$tip.toast('行:' + error1[0] +  ' 数量超出了剩余发料数量！')
								 return 
				}
				if (error2.length>0) {
								 this.$tip.toast('行:' + error2[0] +  ' 数量超出了库存可发料数量！')
								 return
				}
				if (!flag) {
								  this.$tip.toast('数量超出了可发数量！')
								  return
				}
				if (!saveFlag || datas.length == 0) {
								   this.$tip.toast('数据没有输入，无须保存！')
								   return
				}
								console.log('myform',this.myFormData)
								// this.myFormData.womWorkOrderMaterials				
								let param = JSON.parse(JSON.stringify(this.myFormData))
								param.itemChilds = datas
								this.$tip.loading();
								this.$http.post('/wom/womWorkOrderMaterial/receipt-semiproduct-app',param).then(res=>{
									console.log(res)
									this.$tip.loaded();
									if (res.data.success){
										that.tabs[2].data = []
										this.$tip.toast('提交成功')
									}					
								}).catch(()=>{
									this.$tip.loaded();
									this.$tip.error('提交失败')
								});
			},
			onSubmit(status) {
				if (this.activeTab == 2) {
					this.saveSemiProductIssue()
					return
				}
			  let that = this
              let flag = true
			  let saveFlag = false
			  if (!this.tabs[0].data || this.tabs[0].data.length == 0) {
				  this.$tip.toast('没有可提交的数据！')
				  return
			  }
			  if (this.activeTab == 0 && this.selectedItems.length == 0) {
				  this.$tip.toast('没有可提交的数据！')
				  return
			  }
			  // 将选中的行序号存储到 Set 中
			  const selectedIndexSet = new Set(this.selectedItems);
			  const datas = this.tabs[0].data.filter((item, index) => {
			    return selectedIndexSet.has(index) && item.qty > 0;
			  });

              datas.forEach(item => {
				  item.inputQty = item.qtyBal
			  })
			  console.log(datas)
			  let error1 = []
			  let error2 = []
			  datas.forEach((item,index)=>{
				   let balQty = item.qty - 0 - (item.qtyReceipt ? item.qtyReceipt : 0)
				   let inputQty = item.inputQty ? item.inputQty : 0
				   let invQty = item.invQty ? item.invQty : 0
				   if (inputQty > 0) {
				  					  saveFlag = true
				   }
				   if (inputQty > balQty) {
					   error1.push(index+1)
				  					  this.$tip.toast('行:' + (index +1) +  ' 数量超出了剩余发料数量！')
				  					  flag = false
				  					  return
				   }				  
				   if (inputQty  > invQty) {
					   error2.push(index+1)
				  					 this.$tip.toast('行:' + (index + 1) +  ' 数量超出了库存可发料数量！')
				  					 flag = false
				  					 return
				   }
			  })
			  if (error1.length>0) {
				 this.$tip.toast('行:' + error1[0] +  ' 数量超出了剩余发料数量！')
				 return 
			  }
			  if (error2.length>0) {
				 this.$tip.toast('行:' + error2[0] +  ' 数量超出了库存可发料数量！')
				 return
			  }
			  // this.searchMaterialDatas.forEach((item,index) => {
				 //  let balQty = item.qty - 0 - (item.qtyReceipt ? item.qtyReceipt : 0)
				 //  let inputQty = item.inputQty ? item.inputQty : 0
				 //  let invQty = item.invQty ? item.invQty : 0
				 //  if (inputQty > 0) {
					//   saveFlag = true
				 //  }
				 //  if (inputQty > balQty) {
					//   this.$tip.toast('行:' + (index +1) +  ' 数量超出了剩余发料数量！')
					//   flag = false
					//   return
				 //  }				  
				 //  if (inputQty  > invQty) {
					//  this.$tip.toast('行:' + (index + 1) +  ' 数量超出了库存可发料数量！')
					//  flag = false
					//  return
				 //  }
				 //  if (inputQty > 0) {
					// datas.push(item)
				 //  }
			  // })
			  if (!flag) {
				  this.$tip.toast('数量超出了可发数量！')
				  return
			  }
			  if (!saveFlag || datas.length == 0) {
				   this.$tip.toast('数据没有输入，无须保存！')
				   return
			  }
				console.log('myform',this.myFormData)
				// this.myFormData.womWorkOrderMaterials				
				let param = JSON.parse(JSON.stringify(this.myFormData))
				param.womWorkOrderMaterials = datas
				this.$tip.loading();
				this.$http.post('/wom/womWorkOrderMaterial/receipt-app',param).then(res=>{
					console.log(res)
					this.$tip.loaded();
					if (res.data.success){
						that.tabs[0].data = []
						this.$tip.toast('提交成功')
					}					
				}).catch(()=>{
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
			},
			callback(res) {
				console.log("发送状态：",res)
			},
			DateChange(e) {
				this.myFormData.birthday = e.detail.value
			},
			SwitchC(e) {
				this.switchC = e.detail.value
			},
			ChooseImage() {
				var that=this;
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						that.$http.upload(that.$config.apiUrl+that.uploadUrl, {
								filePath: res.tempFilePaths[0],
								name: 'file'
							})
							.then(res => {
								that.myFormData.avatar=res.data.message;
							})
							.catch(err => {
								that.$tip.error(err.data.message)
							});
						this.imgList = res.tempFilePaths
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '召唤师',
					content: '确定要删除这段回忆吗？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
					
				})
			}
		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
		font-weight: 600;
	}
	.button-sp-area {
/*        background: white;
		margin: 11px 88px 10px; */
	}
	.spanStyle {
		    background: red;
		    padding: 3px 5px;
		    word-break: break-word;
		    margin: 3px;
		    border-radius: 5px;
		    color: white;
		    font-size: 12px;
/* 		    cursor: pointer; */
	}
	.spanStyle1 {
			    background: #11c410;
			    padding: 3px 5px;
			    word-break: break-word;
			    margin: 3px;
			    border-radius: 5px;
			    color: white;
			    font-size: 12px;
	/* 		    cursor: pointer; */
		}
	.spanStyle2 {
			    background: #c0c4cc;
			    padding: 3px 5px;
			    word-break: break-word;
			    margin: 3px;
			    border-radius: 5px;
			    color: white;
			    font-size: 12px;
	/* 		    cursor: pointer; */
		}
		.gProgress {
		     color: black;
		     width: 240px;
		     height: 40px;
		     padding: 3px 5px;
		     border-radius: 6px;
		     background: linear-gradient( 90deg, #c30e0e, rgb(194, 199, 199) 70%, transparent 0);
		     border: 1px solid #c0c4cc;
		 }
		.container-btn {
		  display: flex;
		  justify-content: center; /* 水平居中 */
		  align-items: center; /* 垂直居中 */
		  height: 100%; /* 父容器需要有确定的高度 */
		}
	.example-body {
		padding: 10px;
	}

	.scroll-view {
		/* #ifndef APP-NVUE */
		width: 100%;
		height: 100%;
		/* #endif */
		flex: 1
	}

	// 处理抽屉内容滚动
	.scroll-view-box {
		flex: 1;
		position: absolute;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
	}

	.info {
		padding: 15px;
		color: #666;
	}

	.info-text {
		font-size: 14px;
		color: #666;
	}

	.info-content {
		padding: 5px 15px;
	}

	.close {
		padding: 10px;
	}
  .input-border {
    border: 1px solid #ccc; /* 边框颜色可以根据需要自定义 */
    border-radius: 4px; /* 圆角边框 */
    padding: 0px 12px; /* 内边距 */
    width: 120px; /* 输入框宽度 */
    box-sizing: border-box; /* 防止宽度计算错误 */
  }	
  .container {
    padding: 20rpx;
  }
  
  .tabs {
    white-space: nowrap;
    border-bottom: 1rpx solid #eee;
  }
  
  .tab-item {
    display: inline-block;
    padding: 20rpx 30rpx;
    font-size: 28rpx;
    color: #666;
  }
  
  .tab-item.active {
    color: #007AFF;
    border-bottom: 4rpx solid #007AFF;
  }
  
  .content {
    padding: 20rpx 0;
  }
  
  .tab-content {
    font-size: 28rpx;
    color: #333;
  }
</style>
